package com.tj.bo.user.server.dao.impl;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.tj.bo.user.server.dao.UserProductOddsDao;
import com.tj.bo.user.server.entity.UserProductOddsEntity;
import com.tj.bo.user.server.entity.bussiness.UserHaveOddsEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: xulin
 * Date: 2020-07-31
 * Time: 17:26:00.384
 */

@Repository
public class UserProductOddsDaoImpl extends AbstractBaseMapper<UserProductOddsEntity> implements UserProductOddsDao {

    @Override
    public List<UserProductOddsEntity> getByUserCodeAndProductCode(String userCode, String productCode, Integer triggerType) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("productCode", productCode);
        params.put("triggerType", triggerType);
        return getSqlSession().selectList(this.getStatement("getByUserCodeAndProductCode"), params);
    }

    @Override
    public List<UserProductOddsEntity> getByUserProductList(String productCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("productCode", productCode);
        return getSqlSession().selectList(this.getStatement("getByUserProductList"), params);
    }

    @Override
    public List<UserProductOddsEntity> selectUserProductOddsByExpireDate(String userCode, String productCode, Date expireDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("productCode", productCode);
        params.put("expireDate", expireDate);
        return getSqlSession().selectList(this.getStatement("selectUserProductOddsByExpireDate"), params);
    }

    @Override
    public int invalidateUserProductOdds(String userCode, String productCode, Date expireDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("productCode", productCode);
        params.put("expireDate", expireDate);
        return getSqlSession().update(this.getStatement("invalidateUserProductOdds"), params);
    }

    @Override
    public List<UserHaveOddsEntity> selectUserHaveOddsList(Date expireDate, Page page) {
        Map<String, Object> params = new HashMap<>();
        params.put("expireDate", expireDate);
        if (page != null) {
            params.put("page", page);
        }
        return getSqlSession().selectList(this.getStatement("selectUserHaveOddsList"), params);
    }
}